package cn.edu.cug.cs.gtl.docdb.core.impl;

import cn.edu.cug.cs.gtl.common.Pair;
import cn.edu.cug.cs.gtl.docdb.core.DocMeta;
import cn.edu.cug.cs.gtl.docdb.core.DocQuerier;
import cn.edu.cug.cs.gtl.docdb.core.DocRaw;
import cn.edu.cug.cs.gtl.docdb.core.DocStore;

import java.util.List;

public class DocQuerierImpl implements DocQuerier {
    DocStore docStore ;
    public DocQuerierImpl(DocStore docStore){
        this.docStore=docStore;
    }
    @Override
    public Pair<DocMeta, DocRaw> selectByTitle(String title) throws Exception {
        List<DocMeta> docMetas = DocMeta.selectByTitle(docStore.getConnection(), title);
        Pair<DocMeta, DocRaw> docMetaDocRawPair = new Pair<>();
        docMetaDocRawPair.setKey(docMetas.get(0));
        DocRaw docRaw = DocRaw.read(docStore.getStorageManager(), docMetas.get(0).getInternalIdentifier());
        docMetaDocRawPair.setValue(docRaw);
        return docMetaDocRawPair;
    }
}
